import modelExtend from 'dva-model-extend'
import { pageModel } from '@/common/model/BaseModel'
import { getTransList, getTransDetail } from '@/services/property'

export default modelExtend(pageModel, {
  namespace: 'propTrans',
  state: {
    //
    currentItem: {},
    formValues: {},
    //
    showProps: false,
    PropsData: [],
  },
  effects: {
    *fetchList({ payload }, { call, put }) {
      console.log('fetchTransList')
      const res = yield call(getTransList, payload || {})
      yield put({
        type: 'updateState',
        payload: {
          list: res.data.records,
          pagination: {
            showSizeChanger: false,
            showQuickJumper: true,
            showTotal: total => `共 ${total} 条`,
            total: res.data.total,
            current: res.data.current,
            pageSize: res.data.size,
          },
          formValues: payload,
        },
      })
    },

    *fetchProps({ payload }, { call, put }) {
      const res = yield call(getTransDetail, payload)
      if (res && res.success) {
        yield put({
          type: 'updateState',
          payload: {
            PropsData: res.data.items,
          },
        })
      }
    },
  },
})
